<template>
	<joy-page class="joyPage bg-gary">
	<view class="content">
		<view class="bg-white">
			<m-cell title="头像" bottomLine :h_image="userInfo.head_thumb" :isLink="true" @tap="handleChoseImg()"></m-cell>
			<m-cell title="账户名" bottomLine :desc="userInfo.mobile_show" :isLink="false"></m-cell>
			<m-cell title="实名状态" bottomLine :desc="userInfo.is_check===1 ? '已认证' : '未认证'" :isLink="false"></m-cell>
			<m-cell title="性别" bottomLine :desc="userInfo.sex" :isLink="false"></m-cell>
			<m-cell title="投资类型" bottomLine :desc="userInfo.member_type" :isLink="false"></m-cell>
			<m-cell title="会员类型" bottomLine :desc="userInfo.is_vip===1 ? 'vip' : '非vip'" :isLink="false"></m-cell>
		</view>
		<!-- <view class="edit-btn" v-if="customerInfo.status == 'REJECT'">
			<button type="primary" @tap="resetSubmitRegInfo">重新编辑</button>
		</view> -->
		<!-- <view class="save" @tap="handleSave()">保存</view> -->
		<!-- <view class="logout" @tap="logout()">
			退出登录
		</view> -->
	</view>
	</joy-page>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from "vuex"
	import mCell from "@/components/m-cell/m-cell.vue"
	import CheckLogin from "@/common/auth.js"
	import cityData from "@/common/cityData.js"
	export default {
		components: {
			mCell
		},
		computed: {
			...mapState(["userInfo", "token", "openId"]),
			/* cityName() {
				let cityName = this.$mUtils.getCityName(cityData, this.customerInfo.cityNo);
				return cityName;
			} */
		},
		data() {
			return {
				customerStatus: this.$mConstDataConfig.status,
				tempFilePath: ''
			};
		},
		async onLoad(params) {},
		onShow() {
			console.log(this.userInfo)
		},
		methods: {
			// async getCustomerInfo() {
			// 	let customerInfo = await this.$apis.getCustomer();
			// 	this.$store.commit("SET_CUSTOMERINFO", customerInfo);
			// },
			...mapMutations({
				updataHead: 'SET_USERINFO'
			}),

			async logout() {
				await this.$apis.logout();
				uni.clearStorage()
				let res = await this.$apis.getSessionId();
				uni.setStorageSync('sessionId', res.session_id);
				this.$mRouter.push({
					route: this.$mRoutesConfig.login
				})
			},
			handleChoseImg() {
				wx.chooseImage({
					count: 1,
					sizeType: ['compressed'],
					sourceType: ['album', 'camera'],
					success: (res) => {
						console.log(res)
						this.tempFilePath = res.tempFilePaths[0]
						this.userInfo.head_thumb = this.tempFilePath
						this.handleSave()
					}
				})
			},
			//保存头像
			handleSave() {
				let configHeader = {
					"content-type": "application/json",
					"X-requested-With": "XMLHttpRequest",
					"token": this.token,
					"openId": this.openId,
					"Cookie": "PHPSESSID=" + uni.getStorageSync('sessionId')
				}
				wx.showToast({
					icon:"loading",
					title:'保存中',
					duration:2000
				})
				if(this.tempFilePath){
					wx.uploadFile({
						url: this.$apis.updataHeadUrl,
						filePath: this.tempFilePath,
						name: 'imgFile',
						header: configHeader,
						formData: {},
						timeout:3000,
						success: (res) => {
							let userData=JSON.parse(res.data)
							let imgSrc=userData.data.logoSrc
							if(userData.status===200){
								wx.showToast({
									title: userData.msg,
									icon:"success"
								});
								this.userInfo.head_thumb=imgSrc
								// this.$store.commit("SET_USERINFO",this.userInfo)
								this.updataHead(this.userInfo)
								setTimeout(()=>{
									this.$mRouter.switchTab({
										route:this.$mRoutesConfig.person,
										query:{
										}
									})
								},2000)
							}else{
								wx.showToast({
									title: userData.msg,
									icon:"none"
								});
							}
						}
					})
				}else{
					wx.showToast({
						title: '成功',
						icon:"success",
					});
					setTimeout(()=>{
						this.$mRouter.switchTab({
							route:this.$mRoutesConfig.person,
							query:{
							}
						})
					},2000)
					
				}
				
			}

		},
		onNavigationBarButtonTap: function(e) {
			if (e.btnType == "EDIT") {
				if (this.customerInfo.status == "REJECT") {
					this.$mRouter.push({
						route: this.$mRoutesConfig.reg,
						query: {
							type: "RESET"
						}
					})
				} else if (this.customerInfo.status == "WAIT_AUDIT") {
					uni.showToast({
						title: `信息${this.$mConstDataConfig.status[this.customerInfo.status]}`,
						icon: "none"
					})
				} else {
					this.$mRouter.push({
						route: this.$mRoutesConfig.uUserInfo
					})
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.bg-gary{
		background:rgba(246,246,246,1);
	}
</style>
